package main

import (
	"fmt"
)

func rotate(matrix [][]int) {
	n := len(matrix)
	var tmp int
	// 按主对角线翻转
	for i := 0; i < n; i++ {
		for j := 0; j < i; j++ {
			tmp = matrix[i][j]
			matrix[i][j] = matrix[j][i]
			matrix[j][i] = tmp
		}
	}
	// 按竖中轴线翻转
	for i := 0; i < n; i++ {
		for j := 0; j < n/2; j++ {
			tmp = matrix[i][n-1-j]
			matrix[i][n-1-j] = matrix[i][j]
			matrix[i][j] = tmp
		}
	}
}

func main() {
	matrix := [][]int{
		{1, 2, 3},
		{4, 5, 6},
		{7, 8, 9},
	}
	rotate(matrix)
	for _, item := range matrix {
		fmt.Println(item)
	}

}
